!function () {
	layui.config({base: '/layui/lay/modules/'}).use(['upload', 'form'], function () {
		var $ = layui.jquery, upload = layui.upload, form = layui.form;
		upload.render({
			elem: '#appLogo', field: 'appImg',
			accept: 'images', acceptMime: 'images',
			auto: false, size: 1024 * 5
		});
		upload.render({
			elem: '#extendImg', field: 'bgImg',
			accept: 'images', acceptMime: 'images',
			auto: false, size: 1024 * 5
		});
		// 表单验证
		form.on('submit(saveConfig)', function (data) {
			var appLogo = $('input[name=appImg]').val();
			if (!appLogo) {
				layer.alert('请选择APP LOGO图片!', {icon: 0, title: "提醒"});
				return false;
			}
			var extendImg = $('input[name=bgImg]').val();
			if (!extendImg) {
				layer.alert('请选择推广注册背景图片!', {icon: 0, title: "提醒"});
				return false;
			}
			$.ajax({
				async: false, type: 'post', url: '/sysConfig/setting',
				data: new FormData(data.form), contentType: false, processData: false,
				success: function (data) {
					layer.closeAll();
					if (data && data.code == 200)
						layer.alert('更新系统配置信息成功！', {icon: 1, title: "提示"}, function (index) {
							layer.close(index);
							$('a[lay-href="/baseLogPage"]').click();
						});
					else
						layer.alert(data.msg || '更新系统配置信息失败！', {icon: 5, title: "提示"});
				},
				error: function () {
					layer.alert('服务器出错啦！', {icon: 2, title: "错误"});
				}
			});
			return false;
		});
	});
}();